package user

import (
	"errors"
	"time"
)

// 错误定义
var (
	ErrInvalidUsername = errors.New("无效的用户名")
	ErrInvalidPassword = errors.New("无效的密码")
	ErrInvalidEmail    = errors.New("无效的邮箱地址")
)

// User 用户模型
type User struct {
	ID        int64     `json:"id" db:"id"`
	Username  string    `json:"username" db:"username"`
	Password  string    `json:"-" db:"password"` // 存储加密后的密码，不返回给客户端
	Email     string    `json:"email" db:"email"`
	CreatedAt time.Time `json:"created_at" db:"created_at"`
	LastLogin time.Time `json:"last_login" db:"last_login"`
}

// Session 用户会话模型
type Session struct {
	SessionID  string    `json:"session_id" db:"session_id"`
	UserID     int64     `json:"user_id" db:"user_id"`
	VirtualIP  string    `json:"virtual_ip" db:"virtual_ip"`
	CreatedAt  time.Time `json:"created_at" db:"created_at"`
	ExpireAt   time.Time `json:"expire_at" db:"expire_at"`
	LastActive time.Time `json:"last_active" db:"last_active"`
}

// RegisterRequest 用户注册请求
type RegisterRequest struct {
	Username string `json:"username" binding:"required,min=3,max=20"`
	Password string `json:"password" binding:"required,min=6,max=30"`
	Email    string `json:"email" binding:"required,email"`
}

// LoginRequest 用户登录请求
type LoginRequest struct {
	Username string `json:"username" binding:"required"`
	Password string `json:"password" binding:"required"`
}

// Response API响应通用结构
type Response struct {
	Status    string      `json:"status"`
	Message   string      `json:"message,omitempty"`
	Data      interface{} `json:"data,omitempty"`
	ErrorCode int         `json:"error_code,omitempty"`
}

// UserResponse 用户信息响应
type UserResponse struct {
	ID       int64  `json:"user_id"`
	Username string `json:"username"`
}

// SessionResponse 会话信息响应
type SessionResponse struct {
	SessionID string    `json:"session_id"`
	UserID    int64     `json:"user_id"`
	Username  string    `json:"username"`
	VirtualIP string    `json:"virtual_ip"`
	ExpireAt  time.Time `json:"expire_at"`
}

// StatusResponse 用户状态响应
type StatusResponse struct {
	UserID           int64     `json:"user_id"`
	Username         string    `json:"username"`
	VirtualIP        string    `json:"virtual_ip"`
	OnlineSince      time.Time `json:"online_since"`
	SessionExpiresAt time.Time `json:"session_expires_at"`
}
